package fourmiefight.ihm;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;

import org.dyn4j.dynamics.Body;
import org.dyn4j.dynamics.BodyFixture;
import org.dyn4j.geometry.Circle;
import org.dyn4j.geometry.Convex;
import org.dyn4j.geometry.Vector2;

import fourmiefight.abstractionlib2d.IHMItem;

/**
 * Classe graphique de la nourriture
 * @author M1G2
 */
public class FoodView extends IHMItem
{
	public FoodView()
	{
		super();
	}
	
	@Override
	public void render(Graphics2D g, Body body) 
	{
		AffineTransform ot = g.getTransform();
		
		AffineTransform lt = new AffineTransform();
		lt.translate(body.getTransform().getTranslationX() * SCALE, body.getTransform().getTranslationY() * SCALE);
		lt.rotate(body.getTransform().getRotation());

		g.transform(lt);
		for (int i = 0 ; i < body.getFixtureCount() ; i++)
        {
			BodyFixture fixture = body.getFixture(i);
            Convex convex = fixture.getShape();
            if (convex instanceof Circle) 
            {
            	Circle c = (Circle) convex;
                double r = c.getRadius();
                Vector2 cc = c.getCenter();
                int x = (int)Math.ceil((cc.x - r) * SCALE);
                int y = (int)Math.ceil((cc.y - r) * SCALE);
                int w = (int)Math.ceil(r * 2 * SCALE);
                g.setColor(Color.ORANGE);
                g.fillOval(x, y, w, w);
                g.setColor(Color.ORANGE.darker());
                g.drawOval(x, y, w, w);
            }
		}
		g.setTransform(ot);
	}
}
